//
//  Extention+UIBarButtonItem.swift
//  WeiboSwift
//
//  Created by 战场原黑仪 on 16/7/20.
//  Copyright © 2016年 战场原黑仪. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    //便利构造函数
    convenience init(title: String? = nil, imageName: String? = nil, target: AnyObject?, action: Selector) {
        self.init()
        
        let button = UIButton()
        
        //判断title有没有值
        if let tit = title {
            button.setTitle(tit, forState: .Normal)
            button.titleLabel?.font = Normal_Font
            button.setTitleColor(ThemeColor, forState: UIControlState.Normal)
        }
        
        //判断有没有图片
        if let img = imageName {
            button.setImage(UIImage(named: img), forState: .Normal)
        }
        
        //添加点击事件
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        button.sizeToFit()
        
        self.customView = button
    }
    
}